﻿package HG.GameDataTypes
{
	import flash.net.registerClassAlias;
	
	import HG.GameDataTypes.Profile;
	
	public class ProfileStore
	{
		public var m_profiles:Array;
		
		//----------------------------------------------------------------------------------------------------
		public function ProfileStore()
		{
			registerClassAlias("ProfileStore", ProfileStore);
			
			m_profiles = new Array();
		}
		
		//----------------------------------------------------------------------------------------------------
		public function AddProfile(profile:Profile):Boolean
		{
			var profileID:Number = GetProfileIndex(profile.GetName());
			
			if (profileID != -1)
				return false;
				
			m_profiles.push(profile);
			
			return true;
		}
		
		//----------------------------------------------------------------------------------------------------
		public function GetProfile(profileName:String):Profile
		{
			var profileID:Number = GetProfileIndex(profileName);
			
			if (profileID == -1)
				return null;
				
			return m_profiles[profileID];
		}
		
		//----------------------------------------------------------------------------------------------------
		public function GetProfileIndex(profileName:String):Number
		{
			var index:Number = 0;
			var listLength:Number = m_profiles.length;
			
			for (index = 0; index < listLength; ++index)
			{
				var curProfile:Profile = m_profiles[index];
				
				if (curProfile.GetName() == profileName)
					return index;
			}
			
			return -1;
		}
		
		//----------------------------------------------------------------------------------------------------
	}
}